home *** CD-ROM | disk | FTP | other *** search
- #include <exec/types.h>
- #include <exec/exec.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <functions.h>
- #define NL NULL
- void free_pdir();
- static struct FileLock *pdir = NL;
- static struct FileInfoBlock *dir_info = NL;
- char image[200];
- void sr(char *str);
- void CheckFiles(void);
- void end();
- void StripSlash(char *str);
- void CheckForDirs(char PathsFile[]);
- int Strncmp(char *str1,char *str2,int i);
- void free_pdir();
- int NumDirs;
- main(int argc,char *argv[])
- {
- if(argc!=2)
- {
- printf("FileStatus v1.0, written by Joseph Hodge\n");
- printf("Usage: FileStatus <conference path>\n");
- printf(" ie: FileStatus BBS:PD\n");
- printf("\n");
- exit(0);
- }
- strcpy(image,argv[1]);
- sr(image);
- if ((dir_info =(struct FileInfoBlock *)AllocMem((long)sizeof(struct FileInfoBlock),0L)) == NULL)
- {
- printf("Memory Allocation Error.\n");
- Delay(300L);
- exit(0);
- }
- printf("\nFileStatus v1.0, written by Joseph Hodge\n");
- printf("\n\nPerforming validation..\n\n");
- CheckFiles();
- end();
- }
-
- void CheckFiles(void)
- {
- FILE *fi;
- char PathsFile[200];
- char Dirs[200];
- sprintf(Dirs,"%s/ndirs",image);
- sprintf(PathsFile,"%s/Paths",image);
-
- if(access(PathsFile,00))
- {
- printf("Can't locate paths file\n");
- printf("Please check to insure the conference path was correct. IE:\n");
- printf("BBS:PD\n");
- end();
- }
- if(access(Dirs,00))
- {
- printf("Can't locate ndirs file\n");
- printf("Please check to insure the conference path was correct. IE:\n");
- printf("BBS:PD\n");
- end();
- }
- fi=fopen(Dirs,"r");
- fgets(Dirs,80,fi);
- fclose(fi);
- NumDirs=atoi(Dirs);
- fi=fopen(PathsFile,"r");
- while(fgets(PathsFile,80,fi)!=NULL)
- {
- sr(PathsFile);
- StripSlash(PathsFile);
- CheckForDirs(PathsFile);
- }
- fclose(fi);
- }
- void StripSlash(char *str)
- {
- register int i;
- i=strlen(str)-1;
- if(*(str+i)=='/') *(str+i)='\0';
- }
-
- void CheckForDirs(char PathsFile[])
- {
- FILE *fi;
- int NumFiles=0;
- int Missing=0;
- printf("Scanning %s...\n",PathsFile);
- if (! (pdir=(struct FileLock *)Lock(PathsFile,(ULONG)ACCESS_READ)) )
- {
- free_pdir();
- return;
- }
- if ( ! Examine((BPTR)pdir, dir_info) )
- {
- free_pdir();
- return;
- }
- while(ExNext((BPTR)pdir,dir_info))
- {
- if(dir_info->fib_DirEntryType < 0L )
- {
- NumFiles +=1;
- if(!ScanDirs(dir_info->fib_FileName))
- {
- printf("\n %s missing from dir files\n",dir_info->fib_FileName);
- Missing +=1;
- }
- }
- }
- printf(" Total Files %d, Total missing %d\n\n",NumFiles,Missing);
- free_pdir();
- }
-
- int ScanDirs(char str[])
- {
- FILE *fi;
- int i;
- char DirFile[200];
- i=1;
- strupr(str);
- while(i<=NumDirs)
- {
- sprintf(DirFile,"%s/dir%d",image,i);
- if(!access(DirFile,00))
- {
- fi=fopen(DirFile,"r");
- while(fgets(DirFile,100,fi)!=NULL)
- {
- strupr(DirFile);
- if(!Strncmp(DirFile,str,strlen(str)))
- {
- fclose(fi); return(1);
- }
- }
- fclose(fi);
- }
- i++;
- }
- return(0);
- }
- void sr(char *str)
- {
- register int i;
- i=strlen(str)-1;
- while(i)
- {
- if(*(str+i)<=32) *(str+i)='\0'; else return;
- i--;
- }
- }
- int Strncmp(char *str1,char *str2,int i)
- {
- register int j=0;
- while(j<i)
- {
- if(*(str1+j)==*(str2+j)) j +=1; else break;
- }
- if(j==i) return(0); else return(1);
-
- /*
- while(i>0 && *(str1+i-1)==*(str2+i-1)) i -=1;
- return(i);
- */
- }
-
- void end()
- {
- free_pdir();
- if(dir_info!=NL)
- {
-
- FreeMem(dir_info,(long)sizeof(struct FileInfoBlock));
- }
- exit(0);
- }
- void free_pdir()
- {
- if ( pdir )
- {
- UnLock((BPTR)pdir);
- pdir=NL;
- }
- return;
- }